package com.mobimap.nhom9.dto;

/**
 * Class contain Longitude/Latitude of a Point
 * 
 * @author xjumper
 * 
 */
public class LocationDTO {
	private double latitude;
	private double longitude;

	public LocationDTO() {
		this.latitude = 0;
		this.longitude = 0;
	}
	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(latitude);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		temp = Double.doubleToLongBits(longitude);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		LocationDTO other = (LocationDTO) obj;
		if (Double.doubleToLongBits(latitude) != Double
				.doubleToLongBits(other.latitude))
			return false;
		if (Double.doubleToLongBits(longitude) != Double
				.doubleToLongBits(other.longitude))
			return false;
		return true;
	}


	public LocationDTO(double latitude, double longitude) {
		this.latitude = latitude;
		this.longitude = longitude;
	}

	public double getLatitude() {
		return latitude;
	}

	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	public double getLongitude() {
		return longitude;
	}

	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	public static double distance(LocationDTO x, LocationDTO y) {
		double theta = x.getLongitude() - y.getLongitude();
		double dist = Math.sin(Math.toDegrees(x.getLatitude()))
				* Math.sin(Math.toDegrees(y.getLatitude()))
				+ Math.cos(Math.toDegrees(x.getLatitude()))
				* Math.cos(Math.toDegrees(y.getLatitude()))
				* Math.cos(Math.toDegrees(theta));
		dist = Math.acos(dist);
		dist = Math.toDegrees(dist);
		dist = dist * 60 * 1.1515;
		dist = dist * 1.609344;
		return (dist);
	}

	@Override
	public String toString() {
		return "LocationDTO [latitude=" + latitude + ", longitude=" + longitude
				+ "]";
	}
}
